package com.simblog.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.simblog.common.SessionEntity;
import com.simblog.common.constants.Constants;
import com.simblog.common.utils.RedisUtil;
import com.simblog.common.utils.TokenUtil;
import com.simblog.oaknt.domain.User;

@RequestMapping("p/test")
@Controller
public class TestController extends BaseController{
	
	@Autowired
	public RedisUtil redisUtil;
	
	@ResponseBody
	@RequestMapping("set")
	public JSONObject add(){
		User user = new User();
		user.setAccount("1111");
		user.setEmail("111@qq.com");
		
		SessionEntity sessionEntity = new SessionEntity();
		sessionEntity.setUser(user);
		
		String token = TokenUtil.generateToken();
		System.out.println(token);
		
		TokenUtil.setSessionEntity(token, sessionEntity);
		
		return assemblyJson(null, Constants.RESP_SUCCESS, "成功");
		
	}
	
	
	@ResponseBody
	@RequestMapping("get")
	public JSONObject get(){
		//NmI5ZjYwMWYwOGFjNDQ5NWExODdkNzRmMzk1Mzg5NWNfMTQ4MjE1NjAzNzA3MQ==
		User user = TokenUtil.getUser("NmI5ZjYwMWYwOGFjNDQ5NWExODdkNzRmMzk1Mzg5NWNfMTQ4MjE1NjAzNzA3MQ==");
		System.out.println(user.toString());
		return assemblyJson(null, Constants.RESP_SUCCESS, "成功");
	}
	
}
